<?php

    function glue_pices($pices) {

        $cnt = count($pices);

        if (count($pices) > 2):

            $name = "";
            for ($index = 0; $index < $cnt - 1; $index++) :

                $name.= $pices[$index] . '.';

            endfor;

            $name = substr($name, 0, strlen($name) - 1);

            return $name;

        else:
            return $pices[0];
        endif;
    }

    function get_thumbnail($w, $h, $filename) {

        $pices = explode('.', $filename);
        $file = glue_pices($pices); // Fix if filename contains '.' dot in name

        $thumbnail = 'thumbnail/' . $file . '_' . $w . 'x' . $h . '_exacttop.' . $pices[count($pices) - 1];

        return $thumbnail;
    }

    function thumb_filename($filename, $w, $h, $URL, $gallery) {

        $pices = explode('.', $filename);
        $file = glue_pices($pices); // Fix if filename contains '.' dot in name
        $thumbnail = $URL . $gallery . '/thumbnails/' . $file . '_' . $w . 'x' . $h . '.' . $pices[count($pices) - 1];

        return $thumbnail;
    }

    function thumb_filename_cms($filename, $w, $h, $URL, $gallery) {

        $thumbnail = $URL . $gallery . '/thumb_' . $w . 'x' . $h . '/' . $filename;

        return $thumbnail;
    }

    function clean_thumb_filename($filename, $w, $h) {

        $pices = explode('.', $filename);
        $file = glue_pices($pices); // Fix if filename contains '.' dot in name
        $thumbnail = $file . '_' . $w . 'x' . $h . '.' . $pices[count($pices) - 1];

        return $thumbnail;
    }
    
     function thumb_cms($filename, $gallery, $URL, $w, $h) {

        $thumbnail = $URL . $gallery . '/thumb_' . $w . 'x' . $h . '/' . $filename;
        return $thumbnail;
    }

?>
